package org.xwalk.core;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Message;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.ValueCallback;
import android.widget.EditText;
import android.widget.FrameLayout;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;

/**
 * This class notifies the embedder UI events/callbacks.
 */

public class XWalkUIClient   {

    private ArrayList<Object> constructorTypes;
    private ArrayList<Object> constructorParams;
    private ReflectMethod postWrapperMethod;

    /**
     * The type of JavaScript modal dialog.
     * @since 1.0
     */
    public enum JavascriptMessageType {
        /** JavaScript alert dialog. */
        JAVASCRIPT_ALERT,
        /** JavaScript confirm dialog. */
        JAVASCRIPT_CONFIRM,
        /** JavaScript prompt dialog. */
        JAVASCRIPT_PROMPT,
        /** JavaScript dialog for a window-before-unload notification. */
        JAVASCRIPT_BEFOREUNLOAD
    }

    private ReflectMethod enumJavascriptMessageTypeClassValueOfMethod = new ReflectMethod();

    private Object ConvertJavascriptMessageType(JavascriptMessageType type) {
        return enumJavascriptMessageTypeClassValueOfMethod.invoke(type.toString());
    }
    /**
     * Initiator
     * @since 5.0
     */
    public enum ConsoleMessageType {
        DEBUG,
        ERROR,
        LOG,
        INFO,
        WARNING
    }

    private ReflectMethod enumConsoleMessageTypeClassValueOfMethod = new ReflectMethod();

    private Object ConvertConsoleMessageType(ConsoleMessageType type) {
        return enumConsoleMessageTypeClassValueOfMethod.invoke(type.toString());
    }
    /**
     * Initiator
     * @since 4.0
     */
    public enum InitiateBy {
        BY_USER_GESTURE,
        BY_JAVASCRIPT
    }

    private ReflectMethod enumInitiateByClassValueOfMethod = new ReflectMethod();

    private Object ConvertInitiateBy(InitiateBy type) {
        return enumInitiateByClassValueOfMethod.invoke(type.toString());
    }
    /**
     * The status when a page stopped loading
     * @since 2.1
     */
    public enum LoadStatus {
        /** Loading finished. */
        FINISHED,
        /** Loading failed. */
        FAILED,
        /** Loading cancelled by user. */
        CANCELLED
    }

    private ReflectMethod enumLoadStatusClassValueOfMethod = new ReflectMethod();

    private Object ConvertLoadStatus(LoadStatus type) {
        return enumLoadStatusClassValueOfMethod.invoke(type.toString());
    }

    private XWalkCoreWrapper coreWrapper;
    private Object bridge;

    protected Object getBridge() {
        return bridge;
    }


    /**
     * Constructor.
     * @param view the owner XWalkView instance.
     * @since 1.0
     */
    public XWalkUIClient(XWalkView view) {
        constructorTypes = new ArrayList<Object>();
        constructorTypes.add("XWalkViewBridge");

        constructorParams = new ArrayList<Object>();
        constructorParams.add(view);

        reflectionInit();
    }

    /**
     * Request the host application to create a new window
     * @param view The XWalkView which initiate the request for a new window
     * @param initiator How the request was initiated
     * @param callback Callback when once a new XWalkView has been created
     * @return Return true if the host application will create a new window
     * @since 4.0
     */
    public boolean onCreateWindowRequested(XWalkView view, InitiateBy initiator, ValueCallback<XWalkView> callback) {
        try {
            return (Boolean)onCreateWindowRequestedXWalkViewInternalInitiateByInternalValueCallbackMethod.invoke(view.getBridge(), ConvertInitiateBy(initiator), callback);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod onCreateWindowRequestedXWalkViewInternalInitiateByInternalValueCallbackMethod = new ReflectMethod(null, "onCreateWindowRequested");

    /**
     * Notify the host application that an icon is available, send the message to start the downloading
     * @param view The XWalkView that icon belongs to
     * @param url The icon url
     * @param startDownload Message to initiate icon download
     * @since 4.0
     */
    public void onIconAvailable(XWalkView view, String url, Message startDownload) {
        try {
            onIconAvailableXWalkViewInternalStringMessageMethod.invoke(view.getBridge(), url, startDownload);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onIconAvailableXWalkViewInternalStringMessageMethod = new ReflectMethod(null, "onIconAvailable");

    /**
     * Notify the host application of a new icon has been downloaded
     * @param view The XWalkView that icon belongs to
     * @param url The icon url
     * @param icon The icon image
     * @since 4.0
     */
    public void onReceivedIcon(XWalkView view, String url, Bitmap icon) {
        try {
            onReceivedIconXWalkViewInternalStringBitmapMethod.invoke(view.getBridge(), url, icon);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onReceivedIconXWalkViewInternalStringBitmapMethod = new ReflectMethod(null, "onReceivedIcon");

    /**
     * Request display and focus for this XWalkView.
     * @param view the owner XWalkView instance.
     * @since 1.0
     */
    public void onRequestFocus(XWalkView view) {
        try {
            onRequestFocusXWalkViewInternalMethod.invoke(view.getBridge());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onRequestFocusXWalkViewInternalMethod = new ReflectMethod(null, "onRequestFocus");

    /**
     * Notify the client to close the given XWalkView.
     * @param view the owner XWalkView instance.
     * @since 1.0
     */
    public void onJavascriptCloseWindow(XWalkView view) {
        try {
            onJavascriptCloseWindowXWalkViewInternalMethod.invoke(view.getBridge());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onJavascriptCloseWindowXWalkViewInternalMethod = new ReflectMethod(null, "onJavascriptCloseWindow");

    /**
     * Tell the client to display a prompt dialog to the user.
     * @param view the owner XWalkView instance.
     * @param type the type of JavaScript modal dialog.
     * @param url the url of the web page which wants to show this dialog.
     * @param message the message to be shown.
     * @param defaultValue the default value string. Only valid for Prompt dialog.
     * @param result the callback to handle the result from caller.
     * @return true if the client will handle the dialog
     * @since 1.0
     */
    public boolean onJavascriptModalDialog(XWalkView view, JavascriptMessageType type, String url, String message, String defaultValue, XWalkJavascriptResult result) {
        try {
            return (Boolean)onJavascriptModalDialogXWalkViewInternalJavascriptMessageTypeInternalStringStringStringXWalkJavascriptResultInternalMethod.invoke(view.getBridge(), ConvertJavascriptMessageType(type), url, message, defaultValue, ((XWalkJavascriptResultHandler) result).getBridge());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod onJavascriptModalDialogXWalkViewInternalJavascriptMessageTypeInternalStringStringStringXWalkJavascriptResultInternalMethod = new ReflectMethod(null, "onJavascriptModalDialog");

    /**
     * Tell the client to toggle fullscreen mode.
     * @param view the owner XWalkView instance.
     * @param enterFullscreen true if it has entered fullscreen mode.
     * @since 1.0
     */
    public void onFullscreenToggled(XWalkView view, boolean enterFullscreen) {
        try {
            onFullscreenToggledXWalkViewInternalbooleanMethod.invoke(view.getBridge(), enterFullscreen);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onFullscreenToggledXWalkViewInternalbooleanMethod = new ReflectMethod(null, "onFullscreenToggled");

    /**
     * Tell the client to open a file chooser.
     * @param view the owner XWalkView instance.
     * @param uploadFile the callback class to handle the result from caller. It MUST
     *        be invoked in all cases. Leave it not invoked will block all following
     *        requests to open file chooser.
     * @param acceptType value of the 'accept' attribute of the input tag associated
     *        with this file picker.
     * @param capture value of the 'capture' attribute of the input tag associated
     *        with this file picker
     * @since 1.0
     */
    public void openFileChooser(XWalkView view, ValueCallback<Uri> uploadFile, String acceptType, String capture) {
        try {
            openFileChooserXWalkViewInternalValueCallbackStringStringMethod.invoke(view.getBridge(), uploadFile, acceptType, capture);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod openFileChooserXWalkViewInternalValueCallbackStringStringMethod = new ReflectMethod(null, "openFileChooser");

    /**
     * Notify the client that the scale applied to the XWalkView has changed.
     * @param view the owner XWalkView instance.
     * @param oldScale the old scale before scaling.
     * @param newScale the current scale factor after scaling.
     * @since 1.0
     */
    public void onScaleChanged(XWalkView view, float oldScale, float newScale) {
        try {
            onScaleChangedXWalkViewInternalfloatfloatMethod.invoke(view.getBridge(), oldScale, newScale);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onScaleChangedXWalkViewInternalfloatfloatMethod = new ReflectMethod(null, "onScaleChanged");

    /**
     * Give the host application a chance to handle the key event synchronously.
     * e.g. menu shortcut key events need to be filtered this way. If return
     * true, XWalkView will not handle the key event. If return false, XWalkView
     * will always handle the key event, so none of the super in the view chain
     * will see the key event. The default behavior returns false.
     *
     * @param view The XWalkView that is initiating the callback.
     * @param event The key event.
     * @return True if the host application wants to handle the key event
     *         itself, otherwise return false
     *
     * @since 2.1
     */
    public boolean shouldOverrideKeyEvent(XWalkView view, KeyEvent event) {
        try {
            return (Boolean)shouldOverrideKeyEventXWalkViewInternalKeyEventMethod.invoke(view.getBridge(), event);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod shouldOverrideKeyEventXWalkViewInternalKeyEventMethod = new ReflectMethod(null, "shouldOverrideKeyEvent");

    /**
     * Notify the host application that a key was not handled by the XWalkView.
     * Except system keys, XWalkView always consumes the keys in the normal flow
     * or if shouldOverrideKeyEvent returns true. This is called asynchronously
     * from where the key is dispatched. It gives the host application a chance
     * to handle the unhandled key events.
     *
     * @param view The XWalkView that is initiating the callback.
     * @param event The key event.
     *
     * @since 2.1
     */
    public void onUnhandledKeyEvent(XWalkView view, KeyEvent event) {
        try {
            onUnhandledKeyEventXWalkViewInternalKeyEventMethod.invoke(view.getBridge(), event);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onUnhandledKeyEventXWalkViewInternalKeyEventMethod = new ReflectMethod(null, "onUnhandledKeyEvent");

    /**
     * Notify the host application of console message.
     * @param view The XWalkView that initiated the callback.
     * @param message A String containing the console message.
     * @param lineNumber The line number of JavaScript.
     * @param sourceId The link which print log.
     * @param messageType The type of console message.
     * @return Not applicable here. For future use.
     * @since 5.0
     */
    public boolean onConsoleMessage(XWalkView view, String message, int lineNumber, String sourceId, ConsoleMessageType messageType) {
        try {
            return (Boolean)onConsoleMessageXWalkViewInternalStringintStringConsoleMessageTypeMethod.invoke(view.getBridge(), message, lineNumber, sourceId, ConvertConsoleMessageType(messageType));
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod onConsoleMessageXWalkViewInternalStringintStringConsoleMessageTypeMethod = new ReflectMethod(null, "onConsoleMessage");

    /**
     * Notify the host application of a change in the document title.
     * @param view The XWalkView that initiated the callback.
     * @param title A String containing the new title of the document.
     * @since 2.1
     */
    public void onReceivedTitle(XWalkView view, String title) {
        try {
            onReceivedTitleXWalkViewInternalStringMethod.invoke(view.getBridge(), title);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onReceivedTitleXWalkViewInternalStringMethod = new ReflectMethod(null, "onReceivedTitle");

    /**
     * Notify the host application that a page has started loading. This method
     * is called once for each main frame load so a page with iframes or
     * framesets will call onPageLoadStarted one time for the main frame. This also
     * means that onPageLoadStarted will not be called when the contents of an
     * embedded frame changes, i.e. clicking a link whose target is an iframe.
     *
     * @param view The XWalkView that is initiating the callback.
     * @param url The url to be loaded.
     *
     * @since 2.1
     */
    public void onPageLoadStarted(XWalkView view, String url) {
        try {
            onPageLoadStartedXWalkViewInternalStringMethod.invoke(view.getBridge(), url);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onPageLoadStartedXWalkViewInternalStringMethod = new ReflectMethod(null, "onPageLoadStarted");

    /**
     * Notify the host application that a page has stopped loading. This method
     * is called only for main frame. When onPageLoadStopped() is called, the
     * rendering picture may not be updated yet.
     *
     * @param view The XWalkView that is initiating the callback.
     * @param url The url of the page.
     * @param status The status when the page stopped loading.
     *
     * @since 2.1
     */
    public void onPageLoadStopped(XWalkView view, String url, LoadStatus status) {
        try {
            onPageLoadStoppedXWalkViewInternalStringLoadStatusInternalMethod.invoke(view.getBridge(), url, ConvertLoadStatus(status));
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onPageLoadStoppedXWalkViewInternalStringLoadStatusInternalMethod = new ReflectMethod(null, "onPageLoadStopped");

    /**
     * Tell the client to display an alert dialog to the user.
     * WARN: Please DO NOT override this API and onJavascriptModalDialog API in the
     *       same subclass to avoid unexpected behavior.
     * @param view the owner XWalkView instance.
     * @param url the url of the web page which wants to show this dialog.
     * @param message the message to be shown.
     * @param result the callback to handle the result from caller.
     * @return Whether the client will handle the alert dialog.
     * @since 6.0
     */
    public boolean onJsAlert(XWalkView view, String url, String message, XWalkJavascriptResult result) {
        try {
            return (Boolean)onJsAlertXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod.invoke(view.getBridge(), url, message, ((XWalkJavascriptResultHandler) result).getBridge());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod onJsAlertXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod = new ReflectMethod(null, "onJsAlert");

    /**
     * Tell the client to display a confirm dialog to the user.
     * WARN: Please DO NOT override this API and onJavascriptModalDialog API in the
     *       same subclass to avoid unexpected behavior.
     * @param view the owner XWalkView instance.
     * @param url the url of the web page which wants to show this dialog.
     * @param message the message to be shown.
     * @param result the callback to handle the result from caller.
     * @return Whether the client will handle the confirm dialog.
     * @since 6.0
     */
    public boolean onJsConfirm(XWalkView view, String url, String message, XWalkJavascriptResult result) {
        try {
            return (Boolean)onJsConfirmXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod.invoke(view.getBridge(), url, message, ((XWalkJavascriptResultHandler) result).getBridge());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod onJsConfirmXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod = new ReflectMethod(null, "onJsConfirm");

    /**
     * Tell the client to display a prompt dialog to the user.
     * WARN: Please DO NOT override this API and onJavascriptModalDialog API in the
     *       same subclass to avoid unexpected behavior.
     * @param view the owner XWalkView instance.
     * @param url the url of the web page which wants to show this dialog.
     * @param message the message to be shown.
     * @param defaultValue the default value string. Only valid for Prompt dialog.
     * @param result the callback to handle the result from caller.
     * @return Whether the client will handle the prompt dialog.
     * @since 6.0
     */
    public boolean onJsPrompt(XWalkView view, String url, String message, String defaultValue, XWalkJavascriptResult result) {
        try {
            return (Boolean)onJsPromptXWalkViewInternalStringStringStringXWalkJavascriptResultInternalMethod.invoke(view.getBridge(), url, message, defaultValue, ((XWalkJavascriptResultHandler) result).getBridge());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod onJsPromptXWalkViewInternalStringStringStringXWalkJavascriptResultInternalMethod = new ReflectMethod(null, "onJsPrompt");

    /**
     * Notify the host application that the current page would
     * like to show a custom View.
     * @param view is the View object to be shown.
     * @param callback is the callback to be invoked if and when the view is dismissed.
     * @since 7.0
     */
    public void onShowCustomView(View view, CustomViewCallback callback) {
        try {
            onShowCustomViewViewCustomViewCallbackInternalMethod.invoke(view, ((CustomViewCallbackHandler) callback).getBridge());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onShowCustomViewViewCustomViewCallbackInternalMethod = new ReflectMethod(null, "onShowCustomView");

    /**
     * Notify the host application that the current page would
     * like to show a custom View in a particular orientation.
     * @param view is the View object to be shown.
     * @param requestedOrientation An orientation constant as used in
     * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}.
     * @param callback is the callback to be invoked if and when the view is dismissed.
     * @since 7.0
     */
    public void onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback) {
        try {
            onShowCustomViewViewintCustomViewCallbackInternalMethod.invoke(view, requestedOrientation, ((CustomViewCallbackHandler) callback).getBridge());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onShowCustomViewViewintCustomViewCallbackInternalMethod = new ReflectMethod(null, "onShowCustomView");

    /**
     * Notify the host application that the current page would
     * like to hide its custom view.
     * @since 7.0
     */
    public void onHideCustomView() {
        try {
            onHideCustomViewMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onHideCustomViewMethod = new ReflectMethod(null, "onHideCustomView");


    void reflectionInit() {
        XWalkCoreWrapper.initEmbeddedMode();

        coreWrapper = XWalkCoreWrapper.getInstance();
        if (coreWrapper == null) {
            XWalkCoreWrapper.reserveReflectObject(this);
            return;
        }

        int length = constructorTypes.size();
        Class<?>[] paramTypes = new Class<?>[length+1];
        for (int i = 0; i < length; ++i) {
            Object type = constructorTypes.get(i);
            if (type instanceof String) {
                paramTypes[i] = coreWrapper.getBridgeClass((String) type);
                constructorParams.set(i, coreWrapper.getBridgeObject(constructorParams.get(i)));
            } else if (type instanceof Class<?>) {
                paramTypes[i] = (Class<?>) type;
            } else {
                assert(false);
            }
        }

        paramTypes[length] = Object.class;
        constructorParams.add(this);

        ReflectConstructor constructor = new ReflectConstructor(
                coreWrapper.getBridgeClass("XWalkUIClientBridge"), paramTypes);
        try {
            bridge = constructor.newInstance(constructorParams.toArray());
        } catch (UnsupportedOperationException e) {
            return;
        }

        if (postWrapperMethod != null) postWrapperMethod.invoke();

        enumJavascriptMessageTypeClassValueOfMethod.init(null,
                coreWrapper.getBridgeClass("XWalkUIClientInternal$JavascriptMessageTypeInternal"), "valueOf", String.class);
        enumConsoleMessageTypeClassValueOfMethod.init(null,
                coreWrapper.getBridgeClass("XWalkUIClientInternal$ConsoleMessageType"), "valueOf", String.class);
        enumInitiateByClassValueOfMethod.init(null,
                coreWrapper.getBridgeClass("XWalkUIClientInternal$InitiateByInternal"), "valueOf", String.class);
        enumLoadStatusClassValueOfMethod.init(null,
                coreWrapper.getBridgeClass("XWalkUIClientInternal$LoadStatusInternal"), "valueOf", String.class);

        onCreateWindowRequestedXWalkViewInternalInitiateByInternalValueCallbackMethod.init(bridge, null,
                "onCreateWindowRequestedSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), coreWrapper.getBridgeClass("XWalkUIClientInternal$InitiateByInternal"), ValueCallback.class);
        onIconAvailableXWalkViewInternalStringMessageMethod.init(bridge, null,
                "onIconAvailableSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), String.class, Message.class);
        onReceivedIconXWalkViewInternalStringBitmapMethod.init(bridge, null,
                "onReceivedIconSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), String.class, Bitmap.class);
        onRequestFocusXWalkViewInternalMethod.init(bridge, null,
                "onRequestFocusSuper", coreWrapper.getBridgeClass("XWalkViewBridge"));
        onJavascriptCloseWindowXWalkViewInternalMethod.init(bridge, null,
                "onJavascriptCloseWindowSuper", coreWrapper.getBridgeClass("XWalkViewBridge"));
        onJavascriptModalDialogXWalkViewInternalJavascriptMessageTypeInternalStringStringStringXWalkJavascriptResultInternalMethod.init(bridge, null,
                "onJavascriptModalDialogSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), coreWrapper.getBridgeClass("XWalkUIClientInternal$JavascriptMessageTypeInternal"), String.class, String.class, String.class, coreWrapper.getBridgeClass("XWalkJavascriptResultHandlerBridge"));
        onFullscreenToggledXWalkViewInternalbooleanMethod.init(bridge, null,
                "onFullscreenToggledSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), boolean.class);
        openFileChooserXWalkViewInternalValueCallbackStringStringMethod.init(bridge, null,
                "openFileChooserSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), ValueCallback.class, String.class, String.class);
        onScaleChangedXWalkViewInternalfloatfloatMethod.init(bridge, null,
                "onScaleChangedSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), float.class, float.class);
        shouldOverrideKeyEventXWalkViewInternalKeyEventMethod.init(bridge, null,
                "shouldOverrideKeyEventSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), KeyEvent.class);
        onUnhandledKeyEventXWalkViewInternalKeyEventMethod.init(bridge, null,
                "onUnhandledKeyEventSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), KeyEvent.class);
        onConsoleMessageXWalkViewInternalStringintStringConsoleMessageTypeMethod.init(bridge, null,
                "onConsoleMessageSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), String.class, int.class, String.class, coreWrapper.getBridgeClass("XWalkUIClientInternal$ConsoleMessageType"));
        onReceivedTitleXWalkViewInternalStringMethod.init(bridge, null,
                "onReceivedTitleSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), String.class);
        onPageLoadStartedXWalkViewInternalStringMethod.init(bridge, null,
                "onPageLoadStartedSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), String.class);
        onPageLoadStoppedXWalkViewInternalStringLoadStatusInternalMethod.init(bridge, null,
                "onPageLoadStoppedSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), String.class, coreWrapper.getBridgeClass("XWalkUIClientInternal$LoadStatusInternal"));
        onJsAlertXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod.init(bridge, null,
                "onJsAlertSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), String.class, String.class, coreWrapper.getBridgeClass("XWalkJavascriptResultHandlerBridge"));
        onJsConfirmXWalkViewInternalStringStringXWalkJavascriptResultInternalMethod.init(bridge, null,
                "onJsConfirmSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), String.class, String.class, coreWrapper.getBridgeClass("XWalkJavascriptResultHandlerBridge"));
        onJsPromptXWalkViewInternalStringStringStringXWalkJavascriptResultInternalMethod.init(bridge, null,
                "onJsPromptSuper", coreWrapper.getBridgeClass("XWalkViewBridge"), String.class, String.class, String.class, coreWrapper.getBridgeClass("XWalkJavascriptResultHandlerBridge"));
        onShowCustomViewViewCustomViewCallbackInternalMethod.init(bridge, null,
                "onShowCustomViewSuper", View.class, coreWrapper.getBridgeClass("CustomViewCallbackHandlerBridge"));
        onShowCustomViewViewintCustomViewCallbackInternalMethod.init(bridge, null,
                "onShowCustomViewSuper", View.class, int.class, coreWrapper.getBridgeClass("CustomViewCallbackHandlerBridge"));
        onHideCustomViewMethod.init(bridge, null,
                "onHideCustomViewSuper");
    }

}
